var t = require("../../utils/api.js"), e = getApp();

Page({
    data: {
        info: "",
        money: "",
        showLoding: !1
    },
    onLoad: function(a) {
        var o = this, n = a.couponId;
        console.log(n);
        var r = getCurrentPages(), l = (r[r.length - 1], r[r.length - 2].data);
        console.log(l.totalPrice), t.seeUserTicket({
            openid: e.globalData.openid,
            gid: n
        }).then(function(t) {
            if (console.log(t), 0 == t.errno) {
                var e = t.data;
                new Date().getTime();
                console.log(l);
                for (var a = 100 * l.totalPrices / 100, n = [], r = 0; r < e.length; r++) {
                    e[r].old_end_time;
                    var s = 100 * e[r].use_limit / 100;
                    console.log(a, parseFloat(s), r), parseFloat(s) >= 0 && parseFloat(a) < parseFloat(s) || n.push(e[r]);
                }
                o.autosize(e), o.getrange(e), o.setData({
                    info: e,
                    money: l.totalPrices
                });
            } else wx.showToast({
                title: t.message,
                icon: "none",
                duration: 2e3
            }), o.setData({
                showNomore: !0
            });
            o.setData({
                showLoding: !0
            });
        }), wx.setNavigationBarColor({
            frontColor: wx.getStorageSync("basic").topcolor,
            backgroundColor: wx.getStorageSync("basic").topbg
        });
    },
    autosize: function(t) {
        for (var e = this, a = [], o = 0; o < t.length; o++) {
            var n = t[o].cut_price;
            n.split("").length <= 5 && (a[o] = 66), 6 == n.split("").length && (a[o] = 56), 
            7 == n.split("").length && (a[o] = 46), n.split("").length > 7 && (a[o] = 36);
        }
        e.setData({
            autoSize: a
        });
    },
    getrange: function(t) {
        var e = this, a = [];
        console.log(t);
        for (var o = 0; o < t.length; o++) {
            var n = t[o].range;
            if (n.length <= 0 && (a[o] = "全场所有商品可用"), n.length > 0) {
                for (var r = "", l = 0; l < n.length; l++) l == n.length - 1 ? r += n[l].gc_name ? n[l].gc_name : n[l].g_name : r += n[l].gc_name ? n[l].gc_name + "、" : n[l].g_name + "、";
                a[o] = r;
            }
        }
        e.setData({
            getranges: a
        });
    },
    tel: function(t) {
        var e = t.currentTarget.dataset.couid, a = t.currentTarget.dataset.money, o = getCurrentPages(), n = (o[o.length - 1], 
        o[o.length - 2]), r = n.data, l = parseFloat(r.totalPrices) - parseFloat(a);
        console.log(r.totalPrices), console.log(a), l <= 0 && (l = .01), n.setData({
            coupon: e,
            types: 0,
            mon: parseFloat(a)
        }), wx.navigateBack({
            delta: 1
        });
    },
    btn: function(t) {
        wx.showToast({
            title: "不满足使用要求哦，换一个优惠券吧",
            icon: "none",
            duration: 2e3
        });
    },
    todetail: function(t) {
        console.log(t);
        var e = t.currentTarget.dataset.id, a = t.currentTarget.dataset.type;
        wx.navigateTo({
            url: "/pages/personal/couponDetail?id=" + e + "&type=" + a
        });
    }
});